<template>
	<view class="pageBox" :style="{paddingTop: statusBarHeight + 44 + 'px',}">
		<view class="topHead flex-between" :style="{top: statusBarHeight + 'px',}">
			<uni-icons type="back" size="24" @click="goBack"></uni-icons>
			<view class="title">
				转赠积分
			</view>
			<view class="right" @click="onRight">
				赠送说明
			</view>
		</view>
		<view class="main">
			<view class="total">
				<view class="totalText flex-center">
					<view class="totalTextItem">
						总积分
					</view>
					<view class="totalTextItem">
						{{info.creditValue}}
					</view>
				</view>

				<view class="use flex-between">
					<view class="useItem flex-center" v-for="item in tabsList" :key="item.id" @click="onTab(item)">
						<view class="useItemText">
							{{ item.title }}
						</view>
						<view class="useItemText">
							{{ item.num }}
						</view>
					</view>
				</view>
			</view>

			<view class="listBox">
				<view class="listTitle flex-row">
					<view class="title flex-row">
						数量
					</view>
					<view class="title flex-row">
						备注
					</view>
					<view class="title flex-row">
						时间
					</view>
				</view>

				<view class="list">
					<view class="listItem flex" v-for="(item,index) in list" :key="index">
						<view class="item">
							{{item.num}}
						</view>
						<view class="item">
							{{item.remark}}
						</view>
						<view class="item">
							{{item.updatedAt}}
						</view>
					</view>
				</view>
				<u-loadmore :status="status" />
			</view>
		</view>

	</view>
</template>

<script>
	import myPopupTips from "../components/my-popup-tips/my-popup-tips.vue";
	export default {
		components: {
			"my-popup-tips": myPopupTips
		},
		data() {
			return {
				statusBarHeight: "",
				tabsId: -1,
				tabsList: [{
						id: -1,
						title: "冻结",
						status: true,
						num: 0,
					},
					{
						id: 1,
						title: "可用",
						status: false,
						num: 0,
					},
				],
				lastId: 0,
				page: 1,
				list: [],
				end: false,
				status: 'loadmore',
				info: {}

			}
		},
		onLoad() {
			this.statusBarHeight = this.$mySysInfo().top;
			this.getList()
		},
		onReachBottom() {
			this.getList()
		},
		methods: {
			onRight() {
				uni.navigateTo({
					url: '/property/presentation?from=转赠积分&name=transfer_text'
				})
			},
			goBack() {
				const pages = getCurrentPages()
				if (pages.length === 1) {
					if (typeof params === 'number') {
						history.go(-params)
					} else {
						history.back()
					}
				} else {
					uni.navigateBack({
						delta: 1
					});
				}
			},
			onTab(param) {
				this.tabsList.forEach((item) => {
					item.status = false;
					if (item.id == param.id) {
						item.status = true;
						this.tabsId = item.id;
						this.reset()
					}
				})
			},
			reset() {
				this.list = []
				this.lastId = 0
				this.page = 1,
					this.end = false
				this.status = 'loadmore'
				this.getList()
			},
			getList() {
				if (this.end) {
					return
				}
				this.$post({
					module: 'Finance',
					interface: 2100,
					data: {
						lastId: this.lastId,
						page: this.page,
						creditType: 'credit_7',
						direction: this.tabsId
					}
				}).then(res => {
					// console.log(res);
					this.list = [...this.list, ...res.list]
					this.info = res
					this.tabsList[0].num = res.unMoney;
					this.tabsList[1].num = res.usMoney;
					if (res.list.length < 10) {
						this.end = true
					}
					if (res.list.length < 10) {
						this.status = 'nomore';
					} else {
						this.status = 'loading';
					}
					this.page++
					this.lastId = res.lastId
				})
			}


		},
	}
</script>

<style scoped lang="scss">
	.pageBox {
		width: 100%;
		min-height: calc(100vh - var(--window-top));
		background-color: #ffffff;
		
		.topHead {
			background-color: #ffffff;
			height: 88rpx;
			width: 100%;
			padding: 0 32rpx;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 3;
		
			.title {
				font-size: 32rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #000000;
				position: absolute;
				top: 22rpx;
				left: 50%;
				transform: translate(-50%, 0);
			}
		
			.right {
				font-size: 24rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #F2615F;
			}
		}

		.main {

			.total {
				width: 100%;
				height: 354rpx;
				background-image: url("http://www.bobei.shop/static/third/topHeadBg.png");
				background-size: 100% 100%;
				background-repeat: no-repeat;
				padding-top: 76rpx;
				position: relative;

				.totalText {
					flex-direction: column;
					margin: 0 auto;

					.totalTextItem {
						font-size: 36rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: normal;
						color: #FFFFFF;
					}

					.totalTextItem:nth-last-of-type(1) {
						margin-top: 16rpx;
					}
				}

				.use {
					width: 100%;
					height: 120rpx;
					background: linear-gradient(180deg, #FF7270 0%, #F2615F 32%, #F2615F 69%, #FF7270 100%);
					position: absolute;
					bottom: 0;
					left: 0;
					z-index: 1;

					.useItem {
						width: 50%;
						flex-direction: column;

						.useItemText {
							font-size: 32rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: normal;
							color: #FFFFFF;
						}

						.useItemText:nth-last-of-type(1) {
							margin-top: 12rpx;
						}
					}
				}


			}

			

			.listBox {
				width: 100%;
				margin-top: 38rpx;

				.listTitle {
					padding: 0 30rpx;
					.title {
						font-size: 36rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: bold;
						color: #000000;
					}
					.title:nth-of-type(1) {
						width: 26%;
					}
					.title:nth-of-type(2) {
						width: 38%;
					}
					.title:nth-of-type(3) {
						width: 36%;
					}
				}
				.list {
					padding: 20rpx 30rpx 0;

					.listItem {
						align-items: flex-start;
						.item {
							font-size: 24rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: normal;
							color: #666666;
							margin-top: 16rpx;
							word-break: break-all;
						}

						.item:nth-of-type(1) {
							width: 26%;
						}
						.item:nth-of-type(2) {
							width: 38%;
						}
						.item:nth-of-type(3) {
							width: 36%;
						}
					}
				}
			}
		}

	}
</style>
